import{it as e,vn as t}from"./CIxmKYxc4tZcJF.js";var n=t(0),r=new Set,i=!1;function a(){for(let e of[...r])e.flush()}function o(e){if(n.value===0)return;let t=typeof e.composedPath==`function`?e.composedPath():[],i=(t[0]??e.target)instanceof Node?t[0]??e.target:null;for(let e of[...r]){if(!e.rootEls)continue;let t=e.rootEls();!t||t.length===0||i&&t.some(e=>e&&e.contains(i))||e.flush()}}function s(){i||typeof window>`u`||(i=!0,window.addEventListener(`beforeunload`,e=>{n.value>0&&(a(),e.preventDefault(),e.returnValue=``)}),document.addEventListener(`visibilitychange`,()=>{document.visibilityState===`hidden`&&a()}),window.addEventListener(`pagehide`,a),window.addEventListener(`blur`,a),document.addEventListener(`pointerdown`,e=>o(e),{capture:!0,passive:!0}),window.addEventListener(`popstate`,a),window.addEventListener(`hashchange`,a),window.addEventListener(`keydown`,e=>{(e.metaKey||e.ctrlKey)&&!e.altKey&&(e.key===`s`||e.key===`S`)&&(e.preventDefault(),a())},{capture:!0}))}function c(t){let i,a,o=!1;s();function c(e){e!==o&&(o=e,n.value+=e?1:-1)}function l(){clearTimeout(i),clearTimeout(a),i=void 0,a=void 0}function u(){o&&(l(),c(!1),t.commit())}function d(){if(!t.lazy()){t.commit();return}c(!0),clearTimeout(i);let e=t.lazyDelay();e>0&&(i=setTimeout(u,e));let n=t.lazyMaxDelay();n>0&&!a&&(a=setTimeout(u,n))}function f(){l(),c(!1)}let p={flush:u,rootEls:t.rootEls};return r.add(p),e(()=>{u(),r.delete(p)}),{schedule:d,flush:u,cancel:f,isPending:()=>o}}export{c as t};